<?php
/*
Plugin Name: Custom Meta Plugin
Plugin URI: http://wordpress.org/extend/plugins/hello-dolly/
Description: This is a test plugin so I can lean what to do!
Author: Tyler Wiest
Version: 1.1
Author URI: http://www.jtwventures.com
License: GPLv2
*/

// use widgets_init action hook to execute custom function
add_action( 'add_meta_boxes', 'jtw_mbe_create' );

// register our widget
function jtw_mbe_create() {
	// create a custom meta box
	add_meta_box('jtw-meta', 'My Custom Meta Box', 'jtw_mbe_function', 'post', 'normal', 'high');
}

//jtw_testwidget_widget_my_info class
function jtw_mbe_function( $post ) {
	
	// retreive the metadata values if they exist
	$jtw_mbe_name = get_post_meta( $post->ID, '_jtw_mbe_name', true);
	$jtw_mbe_costume = get_post_meta( $post->ID, '_jtw_mbe_costume', true);
	
	echo 'Please Fill in the Information Below';
	?>
	<p>Name: <input type="text" name="jtw_mbe_name" value="<?php echo esc_attr( $jtw_mbe_name ); ?>" /></p>
	<p>Costume:
		<select name="jtw_mbe_costume">
			<option value="vampire" <?php selected( $jtw_mbe_costume, 'vampire' ); ?>>Vampire</option>
			<option value="zombie" <?php selected( $jtw_mbe_costume, 'zombie' ); ?>>Zombie</option>
			<option value="smurf" <?php selected( $jtw_mbe_costume, 'smurf' ); ?>>Smurf</option>
		</select>
	</p>
	<?php	
}

// hook to save the metabox data
add_action( 'save_post', 'jtw_mbe_save_meta');

function jtw_mbe_save_meta( $post_id ) {
	// verify the meta data is set
	if ( isset($_POST['jtw_mbe_name'] ) ) {
		//save the metadata
		update_post_meta( $post_id, '_jtw_mbe_name',
			strip_tags( $_POST['jtw_mbe_name']));
		update_post_meta( $post_id, '_jtw_mbe_costume', 
			strip_tags( $_POST['jtw_mbe_costume']));
	}
}


?>